/**
 * 
 */
package com.qdairlines.common;

import java.net.InetAddress;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author pangyannan
 * @date 2017年6月6日
 * @company QingDao Airlines
 * @description Ip工具类
 */
public class IpUtil {
	private static final Logger logger = LoggerFactory.getLogger(IpUtil.class);
	
	/**
	 * 获取本机名称
	 * @return
	 */
	public static String getLocalName(){
		String localHostName = "localHostName";
        try {
        	localHostName =  InetAddress.getLocalHost().getHostName();
        } catch (Exception e) {
          TraceUtil.error(logger, e);
        }
	    return localHostName;
	}
	
	/**
	 * 获取本机ip地址
	 * @return
	 */
	public static String getLocalAddress(){
		String localHostAddress = "127.0.0.1";
        try {
        	localHostAddress =  InetAddress.getLocalHost().getHostAddress();
        } catch (Exception e) {
          TraceUtil.error(logger, e);
        }
	    return localHostAddress;
	}
	
	/**
	 * 获取本机名@IP
	 * @return
	 */
	public static String getLocalHost(){
		return getLocalName()+"@"+getLocalAddress();
	}
}
